package com.yunxi.service.dubboService.impl.otd;

import com.yunxi.otd.service.OtdDailyPlanDubboService;
import com.yunxi.service.localService.otd.OtdIfProducePlanService;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 日排程 服务实现类
 * </p>
 *
 * @author XUQI
 * @since 2019-05-09
 */
//@Service(version = "${demo.service.version}",
//    application = "${dubbo.application.id}",
//    protocol = "${dubbo.protocol.id}",
//    registry = "${dubbo.registry.id}"
//)
public class OtdDailyPlanDubboServiceImpl implements OtdDailyPlanDubboService {

    @Autowired
    @Qualifier(value = "otdIfProducePlanServiceImpl")
    OtdIfProducePlanService planService;

    @Override
    public List<Map<String, Object>> findWeekPlanDaily(String year, String month, String modelCode) {
        if (StringUtils.isEmpty(year) || StringUtils.isEmpty(month)) {
            throw new RuntimeException("请选择年份、月份");
        }
        List<Integer> days = new ArrayList<>();
        int maxCount = LocalDate.now().withYear(Integer.valueOf(year)).withMonth(Integer.valueOf(month)).lengthOfMonth();
        for (int i = 1; i <= maxCount; i++) {
            days.add(i);
        }
        return planService.findDailyByCode(year, month, modelCode, days);
    }
}
